package com.yykj.prescription.server.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.vo.PageData;
import com.yykj.common.vo.ResultVO;
import com.yykj.prescription.server.dto.template.*;
import com.yykj.prescription.server.service.TemplateService;
import com.yykj.prescription.server.vo.TemplateListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "处方模板相关接口")
@RestController
@RequestMapping("/api/prescription")
public class PrescriptionTemplateController {

    @PostMapping("/template/create")
    @ApiOperation("处方模板 -- 新建")
    @ApiOperationSupport(ignoreParameters = {"chinaList[0].tempId", "chinaList[0].id", "westList[0].tempId", "westList[0].id","chinaUseInfo.tempId"})
    public ResultVO createPrescriptionTemplate(@RequestBody TemplateCreateDTO createDTO) {
        templateService.createPrescriptionTemplate(createDTO);
        return ResultVO.success();
    }

    @ApiOperation("处方模板 -- 删除")
    @DeleteMapping("/template/delete/{id}")
    public ResultVO deletePrescriptionTemplate(@PathVariable Integer id) {
        templateService.deleteTemplate(id);
        return ResultVO.success();
    }

    @PutMapping("/template/edit")
    @ApiOperation("处方模板 -- 修改")
    @ApiOperationSupport(ignoreParameters = {"chinaUseInfo.tempId"} )
    public ResultVO editPrescriptionTemplate(@RequestBody TemplateEditDTO editDTO) {
        templateService.editPrescriptionTemplate(editDTO);
        return ResultVO.success();
    }

    //====================================================================================================
    @ApiOperation("处方模板 -- 明细 -- 删除")
    @DeleteMapping("/template/detail/delete")
    public ResultVO deletePrescriptionTemplateDetail(@RequestBody TemplateDetailDeleteDTO detailDeleteDTO) {
        templateService.deleteTemplateDetail(detailDeleteDTO);
        return ResultVO.success();
    }

    @ApiOperation("处方模板 -- 明细 -- 添加修改")
    @PostMapping("/template/detail/edit")
    @ApiOperationSupport(ignoreParameters = {"chinaList[0].tempId",  "westList[0].tempId" })
    public ResultVO editPrescriptionTemplateDetail(@RequestBody TemplateDetailEditDTO addDTO) {
        templateService.editPrescriptionTemplateDetail(addDTO);
        return ResultVO.success();
    }

    //====================================================================================================
    @ApiOperation("处方模板 -- 列表")
    @GetMapping("/template/list")
    public ResultVO<PageData<TemplateListVO>> listTemplate(TemplateSearchDTO templateSearchDTO) {
        return ResultVO.success(templateService.listTemplate(templateSearchDTO));
    }

    private TemplateService templateService;

    @Autowired
    public void setTemplateService(TemplateService templateService) {
        this.templateService = templateService;
    }
}
